#!/usr/bin/env python
# -*- coding:utf-8 -*-
import json

import requests

if __name__ == "__main__":
    url = "https://movie.douban.com/j/chart/top_list"
    param = {
        'type': 24,
        'interval_id': '100:90',
        'action': '',
        'start': '1',
        'limit': '20'
    }

    # UA伪装
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36 Edg/106.0.1370.52'
    }
    response = requests.get(url, param, headers = headers)
    # 响应数据处理
    dic_obj = response.json()

    # 持久化存储
    fp = open('data/豆瓣.json', 'w', encoding='utf-8')
    # ensure_ascii=False 中文不适用默认的ascii码
    json.dump(dic_obj, fp, ensure_ascii=False)